<template>
  <a-button icon="add" class="table-btn" type="primary" @click="addSource">
    <template #icon>
      <icon-plus />
    </template>
    添加代码源</a-button
  >
  <a-table :data="dataList" :pagination="pagination">
    <template #columns>
      <a-table-column title="代码源" data-index="source">
        <template #cell="{ record }">
          <template v-if="record.sourceType === 1">
            <a-tag v-if="record.source === 1" color="#7816ff">Gitee</a-tag>
            <a-tag v-if="record.source === 2" color="#165dff">gitea</a-tag>
            <a-tag v-if="record.source === 3" color="#165dff">gitlab</a-tag>
          </template>
          <template v-else>
            <a-tag v-if="record.source === 1" color="#7816ff">SVN</a-tag>
          </template>
        </template>
      </a-table-column>
      <a-table-column title="代码源类型" data-index="sourceType">
        <template #cell="{ record }">
          <a-tag v-if="record.sourceType === 1" color="#7816ff">Git</a-tag>
          <a-tag v-else-if="record.sourceType === 2" color="#165dff">Svn</a-tag>
        </template>
      </a-table-column>
      <a-table-column title="代码源地址" data-index="url"></a-table-column>
      <a-table-column title="鉴权ID" data-index="appId"></a-table-column>
      <a-table-column title="鉴权秘钥" data-index="maskSecret"></a-table-column>
      <a-table-column title="操作">
        <template #cell="{ record }">
          <a-button type="primary" style="margin-right: 5px">重新授权</a-button>
          <a-button type="primary" status="danger">删除</a-button>
        </template>
      </a-table-column>
    </template>
  </a-table>
  <add-code-source ref="addCodeSourceRef" />
</template>
<script setup lang="ts">
import { IconPlus, IconDelete } from '@arco-design/web-vue/es/icon'
import { ref, reactive, onMounted } from 'vue'
import { pageListApi } from '@/api/setting/codesetting'
const addCodeSourceRef = ref()
import AddCodeSource from '@/views/setting/components/codeSource/AddCodeSource.vue'
const dataList = ref([])
const pagination = reactive({
  current: 1,
  pageSize: 10,
  total: 0
})

const getTableData = async () => {
  const resp = await pageListApi({ pageNo: pagination.current, pageSize: pagination.pageSize })
  dataList.value = resp.data.dataList
  pagination.total = resp.data.totalCount
}
onMounted(() => {
  getTableData()
})
const addSource = () => {
  addCodeSourceRef.value.open()
}
</script>

<style scoped lang="scss"></style>
